const App = getApp();

Page({

  data: {
    page: 1,      //当前页
    lastPage: 0,  //最后一页
    showMakes: false,
    items: [],
    lists: [],
    roomId: ''
  },
  onLoad: function (options) {
    this.getCate();
    this.getData();
    
  },
  getData(id) {
    let _this = this;
    App._get('room/lists', {
      category_id:id
    }, function (result) {
      _this.setData({
        lists: result.data.list.data
      });
      wx.stopPullDownRefresh()
    });
  },
  getCate(){
    let _this = this;
    App._get('room/category', {}, function (result) {
      _this.setData({
        items: result.data.categoryList
      });
    });
  },
  make(e) {
    this.setData({
      showMakes: true,
      roomId: e.detail
    })
  },
  onPullDownRefresh() {
    this.setData({
      lists: [],
      items: []
    })
    this.getCate();
    this.getData();
  },
  //下一页
  onReachBottom() {
    let page = this.data.page;
    let lastPage = this.data.lastPage;

    if (page < lastPage) {
      page++;
      this.setData({
        page: page
      })
    } else {
      wx.showToast({
        title: '亲，没有更多了',
        icon: 'none'
      })
      return false;
    }
    this.getData();
  },
  getCateId(e){
    let id = e.detail
    this.getData(id)
  }
});